/*
 * @Description:使用 viewImg 图片预览功能
 * @Author: HYH
 * @LastEditors: HYH
 * @LastEditTime: 2022-08-26 16:27:45
 */
import ViewImg from '@/components/ViewImg/index.vue'
import { createVNode, render } from 'vue'
export interface IOption {
  /**是否可以通过点击 modal 关闭组件 */
  closeOnClickModel: boolean
}
interface IMethods {
  close: () => void
  open: (url: string, option?: IOption) => void
}

/**查看图片 */
const viewImg = (url: string, option: IOption = { closeOnClickModel: true }) => {
  const vNode = createVNode(ViewImg)
  render(vNode, document.body)
  const { open, close } = vNode.component?.exposed as IMethods
  open(url, option)
}
export type IViewImg = typeof viewImg
export default viewImg
